import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { PartialConsult, ConsultIllness } from '@/types/consult'
import type { ConsultType } from '@/enums'

// 创建存储用户数据的仓库
export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 保存问诊信息
    const consult = ref<PartialConsult>({})
    // 修改问诊类型信息
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    // 修改极速问诊类型
    const setIllnessType = (illnessType: 0 | 1) => {
      consult.value.illnessType = illnessType
    }
    // 修改科室
    const setDepId = (depId: string) => {
      consult.value.depId = depId
    }
    // 修改病情描述相关的信息
    const setIllness = (illness: ConsultIllness) => {
      ;(consult.value.illnessDesc = illness.illnessDesc),
        (consult.value.illnessTime = illness.illnessTime),
        (consult.value.consultFlag = illness.consultFlag),
        (consult.value.pictures = illness.pictures)
    }
    // 修改患者
    const setPatientId = (id: string) => {
      consult.value.patientId = id
    }
    // 修改优惠券
    const setCouponId = (id: string) => {
      consult.value.couponId = id
    }

    // 清空记录
    const clear = () => {
      consult.value = {}
    }

    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatientId,
      setCouponId,
      clear
    }
  },
  {
    persist: true // 开启持久化 默认存储在localStorage
  }
)
